
import lejos.nxt.*;


public class SensorsDisplay {

	public static void main (String[] args) throws Exception {
		
		// Instantiating Sensor ports:
		UltrasonicSensor ultrasonic = new UltrasonicSensor(SensorPort.S1);
		LightSensor lightsensor		= new LightSensor(SensorPort.S2);
		
		// Calibrate sensors if needed:
		ultrasonic.continuous();
		lightsensor.setFloodlight(false);
		
		while (true)
		{
			if (Button.ESCAPE.isPressed()) {
				break;
			}
			
			// Display information on LCD:
			String s = "US: "+ultrasonic.getDistance()+" cm"; 
			LCD.drawString(s, 0, 1);
			
			s = "LS: "+lightsensor.readNormalizedValue();
			LCD.drawString(s, 0, 2);

			s = "LS%: "+lightsensor.readValue()+"%";
			LCD.drawString(s, 0, 3);
			
			s = "Bat: "+Battery.getVoltageMilliVolt()+"mV";
			LCD.drawString(s, 0, 4);
			
			s = "Mem: "+Runtime.getRuntime().freeMemory()+"bytes";
			LCD.drawString(s, 0, 5);


			Thread.sleep(200);
			LCD.clear();

		}

	}
}
